#include <PersonalInfoDialog.h>

#include <QApplication>
#include <QMessageBox>
//#include <QXmlStreamWriter>
#include <QSettings>
//#include <QFile>

PersonalInfoDialog::PersonalInfoDialog(const PersonalInfo& somePersonalInfo, QWidget * someParent): QDialog(someParent), personalInfo(somePersonalInfo)
{
    this->setWindowTitle(QApplication::translate("PersonalInfoDialog", "Save personal information", 0, QApplication::UnicodeUTF8));
    this->setModal(true);
    this->setFixedWidth(300);

    boxLayout = new QVBoxLayout(this);

    taxPayerNameCheckBox = new QCheckBox(this);
    taxPayerNameCheckBox->setText(QApplication::translate("PersonalInfoDialog", "Tax payer name", 0, QApplication::UnicodeUTF8));
    taxPayerNameCheckBox->setChecked(true);

    boxLayout->addWidget(taxPayerNameCheckBox);

    taxOfficeNameCheckBox = new QCheckBox(this);
    taxOfficeNameCheckBox->setText(QApplication::translate("PersonalInfoDialog", "Tax office name", 0, QApplication::UnicodeUTF8));
    taxOfficeNameCheckBox->setChecked(true);

    boxLayout->addWidget(taxOfficeNameCheckBox);

    taxPayerIdCheckBox = new QCheckBox(this);
    taxPayerIdCheckBox->setText(QApplication::translate("PersonalInfoDialog", "Tax payer id", 0, QApplication::UnicodeUTF8));
    taxPayerIdCheckBox->setChecked(true);

    boxLayout->addWidget(taxPayerIdCheckBox);

    activitesCheckBox = new QCheckBox(this);
    activitesCheckBox->setText(QApplication::translate("PersonalInfoDialog", "Activites", 0, QApplication::UnicodeUTF8));

    boxLayout->addWidget(activitesCheckBox);


    saveButton = new QPushButton(this);
    saveButton->setText(QApplication::translate("PersonalInfoDialog", "Save to config file", 0, QApplication::UnicodeUTF8));

    this->connect(saveButton, SIGNAL(clicked()), this, SLOT(SaveToConfig()));

    boxLayout->addWidget(saveButton);

    this->setLayout(boxLayout);
}

void PersonalInfoDialog::SaveToConfig()
{
    /*
    QFile file(fileName.c_str());
    file.open(QIODevice::WriteOnly);

    QXmlStreamWriter writer(&file);

    writer.setAutoFormatting(true);
    writer.setAutoFormattingIndent(-1);
    */

    QSettings settings("oksamyt", "taxreport");


    //if (taxPayerNameCheckBox->isChecked())
    {
        QString taxPayerName = personalInfo.taxPayerName;
        QMessageBox::information(this, "", personalInfo.taxPayerName);

        settings.setValue("taxPayerName", taxPayerName);

        settings.setValue("taxPayerId", personalInfo.taxPayerId);
        settings.setValue("taxOfficeName", personalInfo.taxOfficeName);

        //settings.setValue("activities", personalInfo.activities);
    }

    //QMessageBox::information(this, "Information saved", QApplication::translate("PersonalInfoDialog", "Your personal information has been saved to taxreport_config.xml ", 0, QApplication::UnicodeUTF8));

    this->close();
}
